import { PageContainer,TableDropdown,ProTable,ProFormSelect } from '@ant-design/pro-components';
import {
    AlipayCircleOutlined,
    LockOutlined,
    PlusOutlined,
    TaobaoCircleOutlined,
    UserOutlined,
    WeiboCircleOutlined,
    SmileOutlined
  } from '@ant-design/icons';
import { Card } from 'antd';
import {
    ProForm,
    ProFormText,
    
  } from '@ant-design/pro-components';
import { Button, message, Select , Space } from 'antd';
import { useState } from 'react';
import { useParams,useLocation } from '@umijs/max';
import { driverInfo } from '@/services/driver';

const iconStyles = {
    marginInlineStart: '16px',
    color: 'rgba(0, 0, 0, 0.2)',
    fontSize: '24px',
    verticalAlign: 'middle',
    cursor: 'pointer',
  };
const waitTime = (time: number = 100) => {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve(true);
      }, time);
    });
  };

function DriverAdd() {
    const Components = {
        ProForm,
      };
    const [type, setType] = useState<keyof typeof Components>('ProForm');
    const queryParams = useParams();
    const userLocation = useLocation();
    const updatedValues = {};
    //let [disab, setDisab] = useState<boolean>(false)
    let [disab, setDisab] = useState(false);
    return(
    <PageContainer title= "司机" >
        <Card>
          <ProForm
            onValuesChange={(changeValues) => console.log(changeValues)}
            onFinish={async (values: any) => {
              const msg = await driverInfo(values)
              console.log(values);
              message.success('提交成功');
            }}
            initialValues={ updatedValues }
            disabled={ disab }
            params={ updatedValues }
            request={async(params) => {
              // 1. 获取参数，如果有参数，按照参数请求后台，如果没有参数，按照默认值请求后台(fid = 0)
              const actionType: string = userLocation.search.indexOf("actionType") > -1 
                ? userLocation.search.split("&")[0].split("=")[1] : "edit";
              
              const formStatus = actionType === "edit" ? false : true;
              setDisab(formStatus);
              const fid = userLocation.search.indexOf("fid") > -1 
                ? userLocation.search.split("&")[1].split("=")[1] : "0";
              const token =  localStorage.getItem('token') + "";
              const queryInfoParams: DriverAPI.QueryInfoParams = {
                fid: fid,
                token: token,
              }
              const msg = await driverInfo(queryInfoParams)
              let fresult: boolean = false;
              let fdata: DriverAPI.Driver = {};
              if (msg) {
                fresult = msg.code == 200 ? true : false;
                fdata = msg.data;
              }
              if (fresult) {
                fdata.fdisable = formStatus;
                return {
                 ...fdata,
                 
                };
              }
            }}
          >
            <ProFormText
              width="md"
              name="fname"
              label='司机姓名'
              tooltip="最长为 24 位"
              placeholder="请输入司机姓名"
            />
            <ProFormText
              width="md"
              name="fidcard"
              label="身份证号"
              placeholder="请输入身份证号"
            />
            <ProFormText
              name="fmobile"
              width="md"
              label="联系方式"
              placeholder="请输入联系方式"
            />
            <ProFormSelect.SearchSelect
              initialValue={'enable'}
              disabled
              name="status"
              mode="single"
              width={'md'}
              label="司机状态"
              style={{ width: 120 }}
              options={[
                { label: '启用', value: 'enable' },
                { label: '禁用', value: 'disable' },
              ]}
            />
          </ProForm>
        </Card>
    </PageContainer>
    )
}

export default DriverAdd;